import re

from django.urls import re_path
from rest_framework import serializers
from users.models import Spit


class CollectSpitSerializer(serializers.ModelSerializer):
    message = serializers.CharField()
    success = serializers.BooleanField()
    parent = serializers.StringRelatedField(many=True)

    def validate(self, attrs):
        content_type = attrs['Content-Type ']
        authorization = attrs['Authorization']
        if not content_type:
            raise serializers.ValidationError('缺少必传参数content_type')
        if re.match(r'[A-Z]\s[a-z0-9]\.([a-z0-9]+)+',authorization):
            raise serializers.ValidationError('缺少必传参数authorization')
        return attrs

    class Meta:
        model = Spit
        fields = '__all__'

# 获取吐槽列表视集
class SpitUitSerializer(serializers.ModelSerializer):
    # next = serializers.NullBooleanField(read_only=True)
    # previous = serializers.NullBooleanField(read_only=True)
    # share = serializers.IntegerField(read_only=True)
    # state = serializers.IntegerField(read_only=True)
    # parent = serializers.NullBooleanField(read_only=True)

    class Meta:
        model = Spit
        fields = '__all__'
